home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
strlib12.arc
/
STRLIB.DOC
< prev
next >
Wrap
Text File
|
1991-01-20
|
13KB
|
486 lines
StrLib v1.2 (c) 1990, 1991 Serious Cybernetics
Turbo Pascal(tm) 5.5 String Library Unit
by Scott Davis
-------------------------------------------------------------------------------
The following files should be included in STRLIB12.ZIP :
STRLIB.DOC StrLib Documentation
STRLIB.TPU StrLib Unit
-------------------------------------------------------------------------------
STRLIB.TPU contains a library of string functions for use with Turbo
Pascal (tm) 5.5
The following functions are defined in StrLib :
FUNCTION All(s : STRING; n : BYTE) : STRING;
FUNCTION Center(s : STRING; n : BYTE) : STRING;
FUNCTION CenterLoc(s : STRING; w : BYTE) : BYTE;
FUNCTION Clip(s : STRING) : STRING;
FUNCTION FullClip(s : STRING) : STRING;
FUNCTION GetFirst(s : STRING) : STRING;
FUNCTION GetLast(s : STRING) : STRING;
FUNCTION Hex(s : STRING) : BOOLEAN;
FUNCTION HexStr(i : INTEGER) : STRING;
FUNCTION HexVal(s : STRING) : INTEGER;
FUNCTION Left(s : STRING) : STRING;
FUNCTION LeftClip(s : STRING) : STRING;
FUNCTION LeftPad(s : STRING; n : BYTE) : STRING;
FUNCTION LeftStr(s : STRING; n : BYTE) : STRING;
FUNCTION LowCase(s : CHAR) : CHAR;
FUNCTION Lower(s : STRING) : STRING;
FUNCTION MakeName(s1 : STRING; s2 : STRING; r : BOOLEAN) : STRING;
FUNCTION Normal(s : STRING) : STRING;
FUNCTION Numeric(s : STRING) : BOOLEAN;
FUNCTION NumVal(s : STRING) : INTEGER;
FUNCTION Right(s : STRING) : STRING;
FUNCTION RightPad(s : STRING; n : BYTE) : STRING;
FUNCTION RightStr(s : STRING; n : BYTE) : STRING;
FUNCTION Spaces(n : BYTE) : STRING;
FUNCTION NumStr(i : INTEGER) : STRING;
FUNCTION Upper(s : STRING) : STRING;
FUNCTION ZeroClip(s : STRING) : STRING;
FUNCTION ZeroPad(s : STRING; n : BYTE) : STRING;
-------------------------------------------------------------------------------
FUNCTION All(s : STRING; n : BYTE) : STRING;
"All" will return a string of "n" repetitions of "s". Examples :
WriteLn(All('*',7));
will display '*******'.
WriteLn(All('[]',10));
will display '[][][][][][][][][][]'.
-------------------------------------------------------------------------------
FUNCTION Center(s : STRING; n : BYTE) : STRING;
"Center" will return a "s" centered in a string of "n" length. Leading and
trailing spaces will be ignored. Examples :
WriteLn(Center('This',10));
will display ' This '.
WriteLn(Center(' This',10));
will display ' This '.
-------------------------------------------------------------------------------
FUNCTION CenterLoc(s : STRING; w : BYTE) : BYTE;
"CenterLoc" will return the position to display "s" on screen of "w" width.
The entire length of "s" is considered (including leading and trailing spaces).
Examples :
XLoc := CenterLoc('Print',80);
will set XLoc equal to 38.
XLoc := CenterLoc('Print ',40);
will set XLoc equal to 16.
-------------------------------------------------------------------------------
FUNCTION Clip(s : STRING) : STRING;
"Clip" will return a string of "s" with all trailing spaces removed.
Examples :
WriteLn('Well'+Clip('Hello ')+'There');
will display 'WellHelloThere'.
WriteLn('Well'+Clip(' Hello ')+'There');
will display 'Well HelloThere'.
-------------------------------------------------------------------------------
FUNCTION FullClip(s : STRING) : STRING;
"FullClip" will return a string of "s" with all leading and trailing spaces
removed. Examples :
WriteLn('Well'+FullClip('Hello ')+'There');
will display 'WellHelloThere'.
WriteLn('Well'+FullClip(' Hello ')+'There');
will display 'WellHelloThere'.
-------------------------------------------------------------------------------
FUNCTION GetFirst(s : STRING) : STRING;
"GetFirst" will return the first name of the full name "s". Leading and
trailing blanks are ignored. Examples :
WriteLn(GetFirst('Gilbert N. Bates'));
will display 'Gilbert'.
WriteLn(GetFirst(' Steve "Evil Twin" Pogo '));
will display 'Steve'.
-------------------------------------------------------------------------------
FUNCTION GetLast(s : STRING) : STRING;
"GetLast" will return the last name of the full name "s". Leading and
trailing blanks are ignored. Examples :
WriteLn(GetLast('Gilbert N. Bates'));
will display 'Bates'.
WriteLn(GetLast(' Steve "Evil Twin" Pogo '));
will display 'Pogo'.
-------------------------------------------------------------------------------
FUNCTION Hex(s : STRING) : BOOLEAN;
"Hex" will return true if "s" is a valid hexadecimal number. Leading and
trailing blanks are ignored. Example :
HexTest := FALSE;
WHILE HexTest = FALSE DO BEGIN
WriteLn('Enter a hex value : ');
ReadLn(HexEntry);
HexTest := Hex(HexEntry);
END;
will prompt until a valid hex string is entered.
-------------------------------------------------------------------------------
FUNCTION HexStr(i : INTEGER) : STRING;
"HexStr" will return a string containing a hexadecimal representation of "i".
Examples :
WriteLn(HexStr(191));
will display 'BF'.
WriteLn(HexStr(32767));
will display '7FFF'.
-------------------------------------------------------------------------------
FUNCTION HexVal(s : STRING) : INTEGER;
"HexVal" will return the numeric value of the hex string "s". Examples :
TestVal := HexVal('1b');
will set TestVal equal to 27.
TestVal := HexVal('d') + 2;
will set TestVal equal to 15.
-------------------------------------------------------------------------------
FUNCTION Left(s : STRING) : STRING;
"Left" will return a string "s" left justified within the length of "s".
Example :
WriteLn(Left(' Hello ')+'There');
will display 'Hello There'.
-------------------------------------------------------------------------------
FUNCTION LeftClip(s : STRING) : STRING;
"LeftClip" will return a string of "s" with all leading spaces removed.
Examples :
WriteLn('Well'+LeftClip('Hello ')+'There');
will display 'WellHello There'.
WriteLn('Well'+LeftClip(' Hello ')+'There');
will display 'WellHello There'.
-------------------------------------------------------------------------------
FUNCTION LeftPad(s : STRING; n : BYTE) : STRING;
"LeftPad" will pad string s with leading spaces to a length of "n".
Example :
WriteLn(LeftPad('Hello',10)+'There');
will display ' HelloThere'.
-------------------------------------------------------------------------------
FUNCTION LeftStr(s : STRING; n : BYTE) : STRING;
"LeftStr" will return the left "n" characters of string "s". Example :
WriteLn(LeftStr('ABCDEFG',3));
will display 'ABC'.
-------------------------------------------------------------------------------
FUNCTION LowCase(s : CHAR) : CHAR;
"LowCase" will return character "s" forced to lower case. This function is
the opposite of the Turbo Pascal function UpCase. Examples :
WriteLn(LowCase('H'));
will display 'h'.
WriteLn(LowCase('j'));
will display 'j'.
-------------------------------------------------------------------------------
FUNCTION Lower(s : STRING) : STRING;
"Lower" will return string "s" forced to lower case. Example :
WriteLn(Lower('This is an EXAMPLE of using Lower');
will display 'this is an example of using lower'.
-------------------------------------------------------------------------------
FUNCTION MakeName(s1 : STRING; s2 : STRING; r : BOOLEAN) : STRING;
"MakeName" will return a full name composed of first name "s1" and last
name "s2". If "r" is true, "MakeName" will return the string in reverse
order (last name first, divided by a comma). Leading and trailing blanks
are ignored. Examples :
WriteLn(MakeName(' Steve ',' Pogo ',FALSE));
will display 'Steve Pogo'.
WriteLn(MakeName(' Gilbert ',' Bates ',TRUE));
will display 'Bates, Gilbert'.
-------------------------------------------------------------------------------
FUNCTION Normal(s : STRING) : STRING;
"Normal" will return a normalized (first letter of each word is upper and all
others are lower) string of "s". Example :
WriteLn(Normal('THIS IS YOUR LAST CHANCE');
will display 'This Is Your Last Chance');
-------------------------------------------------------------------------------
FUNCTION Numeric(s : STRING) : BOOLEAN;
"Numeric" will return true if "s" contains a valid numeric value. Leading
and trailing blanks are ignored. Example :
IF NOT Numeric(EntryStr) THEN WriteLn('Not Numeric');
will display 'Not Numeric' if the string EntryStr is not a valid numeric.
-------------------------------------------------------------------------------
FUNCTION NumVal(s : STRING) : INTEGER;
"NumVal" will return the integer value of numeric string "s". Leading and
trailing blanks are ignored. Examples :
TestVal := NumVal(' 32 ');
will set TestVal equal to 32.
TestVal := NumVal('4')+4;
will set TestVal equal to 8.
TestVal := NumVal('9j');
will set TestVal equal to 0.
-------------------------------------------------------------------------------
FUNCTION Right(s : STRING) : STRING;
"Right" will return a string "s" right justified within the length of "s".
Example :
WriteLn(Left(' Hello ')+'There');
will display ' HelloThere'.
-------------------------------------------------------------------------------
FUNCTION RightPad(s : STRING; n : BYTE) : STRING;
"RightPad" will pad string "s" with trailing spaces to a length of "n".
Example :
WriteLn(LeftPad('Hello',10)+'There');
will display 'Hello There'.
-------------------------------------------------------------------------------
FUNCTION RightStr(s : STRING; n : BYTE) : STRING;
"RightStr" will return the right "n" characters of string "s". Example :
WriteLn(RightStr('ABCDEFG',3));
will display 'EFG'.
-------------------------------------------------------------------------------
FUNCTION Spaces(n : BYTE) : STRING;
"Spaces" will return a string of "n" spaces. Example :
WriteLn('Hello'+Spaces(5)+'There');
will display 'Hello There'.
-------------------------------------------------------------------------------
FUNCTION NumStr(i : INTEGER) : STRING;
"NumStr" will return a string containg "i". Example :
WriteLn('The answer is '+NumStr(42)+'.');
will display 'The answer is 42.'.
-------------------------------------------------------------------------------
FUNCTION Upper(s : STRING) : STRING;
"Upper" will return string "s" forced to upper case. Example :
WriteLn(Upper('This is an EXAMPLE of using Upper');
will display 'THIS IS AN EXAMPLE OF USING UPPER'.
-------------------------------------------------------------------------------
FUNCTION ZeroClip(s : STRING) : STRING;
"ZeroClip" will return string "s" with leading zeros removed. Examples :
WriteLn(ZeroClip('00000099'));
will display '99'.
WriteLn(ZeroClip('01008'));
will display '1008'.
WriteLn(ZeroClip('000'));
will display '0'.
-------------------------------------------------------------------------------
FUNCTION ZeroPad(s : STRING; n : BYTE) : STRING;
"ZeroPad" will return string "s" padded with leading zeros to length "n".
Examples :
WriteLn(ZeroPad('14',9));
will display '000000014'.
WriteLn(ZeroPad('009',4));
will display '0009'.
-------------------------------------------------------------------------------
StrLib is shareware. You may copy and distribute STRLIB12.ZIP freely, as well
as use it for development of programs for your own use, to give away or to
sell. All I ask is that you include all of the original files, unmodified,
and that you do not charge for the distribution of StrLib itself.
If you like StrLib and use it, any donation would be greatly appreciated
($10 suggested). This would help to encourage future enhancements to this
unit and the writing of others like it.
Questions, comments, and suggestions are welcome.
Send E/Mail to Scott Davis
Phoenix Starfighter BBS (2400 bps)
Phone (404) 869-3410
FidoNet Node 1:3616/20
Send US Mail to Scott Davis
Rt. 2 Box 95
County Line Drive
Lula, GA 30554
-------------------------------------------------------------------------------
I'd like to thank Danny Sosebee (Sysop of Phoenix Starfighter) for
allowing me to use his BBS as a way to receive suggestions and comments
regarding StrLib. Also, I'd like to thank Ed Ivey (Sysop of Ed's Place
BBS - 404/532-1978 - FidoNet Node 1:3616/1) for his continued support
and assistance in distributing my little software "projects".
------------------------------------------------------------------------------
StrLib (c) 1990, 1991 Serious Cybernetics
Turbo Pascal (c) 1983, 1989 Borland International